package com.gitee.loyo.act.remote

import com.gitee.loyo.*
import com.gitee.loyo.act.*
import java.math.BigDecimal
import java.time.LocalDateTime

open class TUserModelCompanionDao(
    ref: ModelCompanionRef<TUserModel, User> = ModelCompanionRef()
): RemoteModelCompanion<TUserModel, User>(ref), UserCompanion by ref.dao()

class TUserModel(
    @Transient @com.gitee.loyo.PrimaryKey(autoIncrement = true)
    val user_id: BIGINT,
    @Transient @com.gitee.loyo.NotNull @com.gitee.loyo.Length(12)
    val user_name: VARCHAR,
    @Transient @com.gitee.loyo.NotNull @com.gitee.loyo.Default("1")
    val sex: INT,
    @Transient @com.gitee.loyo.NotNull @com.gitee.loyo.Default("true")
    val active: TINYINT,
): Model<TUserModel, User>("t_user"){

    companion object: TUserModelCompanionDao()
}

data class User(
    var userId: Long? = null,
    var userName: String? = null,
    var sex: Int? = null,
    var active: Boolean? = null,

    ): UserDao() {

    @delegate: Transient val profile: UserProfile? by lazy { rel() }

    @delegate: Transient val jobs: List<Job> by lazy { rel() }
}

open class UserDao(
    ref: RecordRef<TUserModel, User> = RecordRef()
): RemoteRecord<TUserModel, User>(ref), UserMapper by ref.dao()

interface UserMapper{

    fun findAllFromSameUserName(): List<User>
}

interface UserCompanion{

    fun removeAllAdmin(): Int
}

///////////////////////////////////////////////

class TJobModel(
    @Transient @com.gitee.loyo.PrimaryKey
    val employee_id: BIGINT,
    @Transient @com.gitee.loyo.PrimaryKey
    val user_id: BIGINT,
    @Transient @com.gitee.loyo.Length(12)
    val title: VARCHAR,
    @Transient @com.gitee.loyo.NotNull
    val salary: DECIMAL,
): Model<TJobModel, Job>("t_job"){

    companion object: TJobModelCompanionDao()
}

open class TJobModelCompanionDao(
    ref: ModelCompanionRef<TJobModel, Job> = ModelCompanionRef()
): RemoteModelCompanion<TJobModel, Job>(ref)

open class JobDao(
    ref: RecordRef<TJobModel, Job> = RecordRef()
): RemoteRecord<TJobModel, Job>(ref)

data class Job(
    var employeeId: Long? = null,
    var userId: Long? = null,
    var title: String? = null,
    var salary: BigDecimal? = null,
): JobDao()

////////////////////////////////////////////

class TUserProfileModel(
    @Transient @com.gitee.loyo.PrimaryKey
    val user_id: BIGINT,
    @Transient @com.gitee.loyo.Length(12)
    val education: VARCHAR,
): Model<TUserProfileModel, UserProfile>("t_user_profile"){

    companion object: TUserProfileModelCompanionDao()
}

open class TUserProfileModelCompanionDao(
    ref: ModelCompanionRef<TUserProfileModel, UserProfile> = ModelCompanionRef()
): RemoteModelCompanion<TUserProfileModel, UserProfile>(ref)

data class UserProfile(
    var userId: Long? = null,
    var education: String? = null,
): UserProfileDao()

open class UserProfileDao(
    ref: RecordRef<TUserProfileModel, UserProfile> = RecordRef()
): RemoteRecord<TUserProfileModel, UserProfile>(ref)

///////////////////////////////////////////////

class TDailyLogModel(
    @Transient @com.gitee.loyo.PrimaryKey
    val log_id: BIGINT,
    @Transient @com.gitee.loyo.Length(0)
    val log_time: TIMESTAMP,
): Model<TDailyLogModel, DailyLog>("t_daily_log_"){

    companion object: TDailyLogModelCompanionDao()
}

open class TDailyLogModelCompanionDao(
    ref: ModelCompanionRef<TDailyLogModel, DailyLog> = ModelCompanionRef()
): RemoteModelCompanion<TDailyLogModel, DailyLog>(ref)

data class DailyLog(
    var logId: Long? = null,
    var logTime: LocalDateTime? = null,
): DailyLogDao()

open class DailyLogDao(
    ref: RecordRef<TDailyLogModel, DailyLog> = RecordRef()
): RemoteRecord<TDailyLogModel, DailyLog>(ref)